************************************************
Replication files for "The Path of Law: Legal Uncertainty and Issues of First Impression in the U.S. Courts of Appeals," American Political Science Review
Anthony R. Taboni, ataboni@princeton.edu
************************************************

***************************************
***Instructions:

To replicate tables and figures in paper
1) Open main.R and update working directory to source file location
2) Run main.R which will run 03_Main_Analyses.R, 04_Fiugre_A1_Simulations.R, 05_Figure_A2_Simulations.R, 06_Robustness_Check_CF_Scores.R, and 08_Figure_B2.R
3) This will produce the figures and tables in the paper and supplementary analysis

To reconstruct Taboni_COFI_Analysis.xlsx:
1) Set directory to Code folder and run Run 01_JCS_to_nid.py in terminal which will match JCS scores to FJC nids
2) Set working directory to replication folder and run 02_Match_JCS_to_Judges.R which will match JCS scores to panels and calculate medians

To reconstruct Split_Aversion_XXXX_bound.csv:
1) Run 07_Generate_Figure_B2.nb

Files for proofs of propositions
1) Proposition_2.nb will show quantities in Proposition 2 are less than or equal to 0
2) Proposition_3.nb will show quantities in Proposition 3 are greater than or equal to 0

***************************************






***Table of Contents

* main.R --- Master file which runs scripts in the `Code` folder needed to produce figures and tables in the main paper and appendix


* `documentation` folder
	** Codebook.txt - Codebook with a description for each variable included in `Taboni_Cofi_Analysis.xlsx`
	** Liberal_Disposition_Coding.xlsx - Description of each issue of first impression and which position is coded as the liberal position


* `Data` folder:
	** Taboni_COFI_Analysis.xlsx - Primary dataset, information on cases of first impression, position taken by panel, and ideology of the panel
	** Split_Aversion_lower_bound.csv - Lower bound for figure B2. Generated by 07_Generate_Figure_b2.nb
	** Split_Aversion_upper_bound.csv - Upper bound for figure B2. Generated by 07_Generate_Figure_b2.nb
	** `raw` folder:
		*** Bonica_Sen_Judicial_Ideology_2017.csv - CF Scores for judges as calculated by Bonica and Sen (2017):   
		https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/RPZLMY/E6ZRBI&version=1.0
		*** Bonica_Sen_Judicial_Ideology_2021.csv - Updated CF Scores for judges as calculated by Bonica and Sen (2021). Does not include indicator for whether score is imputed: 	
			https://www.openicpsr.org/openicpsr/project/128663/version/V2/view?path=/openicpsr/128663/fcr:versions/V2/fjc_jep.csv&type=file#
		*** Boyd_District_Court_JCS.csv: JCS Scores for District Court Judges from Boyd: https://sites.wustl.edu/clboyd/research/
		*** FJC_Judge_Data.xlsx - Judge information from the Federal Judicial Center: https://www.fjc.gov/history/judges
		*** Hand_Coded_Medians.csv - Median JCS scores hand calculated for 34 cases where merge is unsuccessful
		*** JCS_COA_Epstein_et_al.xlsx - JCS scores for Court of Appeals Judges from Epstein et al. (2007): https://epstein.wustl.edu/jcs
		*** jcs_medians.csv - Circuit median JCS scores from Epstein et al. (2007): https://epstein.wustl.edu/jcs
		*** jcs_nid.csv - Match of JSC scores to FJC nids. Generated by 01_JCS_to_nid.py
		*** jsc_supreme_court_2024_wide.csv - JCS score for Supreme Court Justices from Epstein et al. (2007): https://epstein.wustl.edu/jcs
		*** Judges_in_Circuit.csv - List of nids in each circuit in each year, used to calculate CFScore circuit medians
		*** Taboni_COFI_Cases.xlsx - Information on cases of first impression, position taken by panel, and members of the panel 


* `Code` folder
	** 01_JCS_to_nid.py - Matches JCS data with FJC nids. Generates jcs_nid.csv
	** 02_Match_JCS_to_Judges.R - Matches ideology to panels. Generates Taboni_COFI_Analysis.xlsx
	** 03_Main_Analyses.R - Run analysis for test of paper and for Tables C1-C3 in Appendix
	** 04_Figure_A1_Simulations.R - Generate plots for Figure A1. Seed is set before each plot to (08540) 
	** 05_Figure_A2_Simulations.R - Generate plots for Figure A2. Seed is set before each plot to (08540) 
	** 06_Robustness_Check_CF_Scores.R - Robustness check using CFScores. Creates table C4
	** 07_Generate_Figure_B2.nb - Generates bounds for Figure B2
	** 08_Figure_B2.R - Creates Figure B2
	** Proposition_2.nb - Show that quantities in the proof of proposition 2 are less than 0
	** Proposition_3.nb - Show that quantities in the proof of proposition 3 are greater than 0

* `Plots` folder
	** Figure_8A.pdf - Distribution of decisions across circuit: 03_Main_Analyses.R produces Figure_8A.pdf
	** Figure_8B.pdf - Distribution of decisions across years: 03_Main_Analyses.R produces Figure_8B.pdf
	** Figure_9A.pdf - Number of circuits that decide an issue: 03_Main_Analyses.R produces Figure_9A.pdf
	** Figure_9B.pdf - Number of circuits that decide an issue, only among splits: 03_Main_Analyses.R produces Figure_9B.pdf
	** Figure_10.pdf - Split Hazard Rate: 03_Main_Analyses.R produces Figure_10.pdf
	** Figure_11A.pdf - Predicted probability of circuit split: 03_Main_Analyses.R produces Figure_11A.pdf
	** Figure_11B.pdf - Difference in predicted probability: 03_Main_Analyses.R produces Figure_11B.pdf
	** Figure_12.pdf - Probability of subsequent agreement: 03_Main_Analyses.R produces Figure_12.pdf
	** Figure_13.pdf - When minority position is chosen: 03_Main_Analyses.R produces Figure_13.pdf
	** Figure_B2.pdf - Effect of split aversion on behavior: 08_Figure_B2.R produces Figure_B2.pdf
	** Figure A1: Prob_Subsequent_Agreement_XX.pdf - Probability of subsequent agreement simulations: 04_Figure_A1_Simulations.R produces Prob_Subsequent_Agreement_XX.pdf
	** Figure A2: Prop_Minority_Decisions_XX.pdf - Proporition of minority decisions : 05_Figure_A2_Simulations.R produces Prop_Minority_Decisions_XX.pdf

* `Tables` folder
	For all tables, formatting is changed in manuscript .tex file to signify inclusion of fixed effects.
	** Table 1: t1.tex  - Results from main analysis: 03_Main_Analyses.R produces t1.tex 
	** Table C1: c1.tex - Results on the effect of period on subsequent agreement: 03_Main_Analyses.R produces c2.tex 
	** Table C2: c2.tex - Results on the effect of period on the proportion of minority decisions: 03_Main_Analyses.R produces c3.tex 
	** Table C3: c3.tex - Additional fixed effects specifications for main results: 03_Main_Analyses.R produces c3.tex 
	** Table C4: c4.tex - CF score robustness results: 06_Robustness_Check_CF_Scores.R produces c4.tex 

*******************************************************************
***Software
All analyses were performed using macOS Sequoia Version 15.3.2

********
R - 4.3.2

**R packages
texreg_1.39.3 
estimatr_1.0.0         
marginaleffects_0.16.0 
ggpattern_1.0.1        
readxl_1.4.3          
latex2exp_0.9.6 
lubridate_1.9.3   
forcats_1.0.0  
stringr_1.5.1
dplyr_1.1.4   
purrr_1.0.2
readr_2.1.4
tidyr_1.3.1 
tibble_3.2.1 
ggplot2_3.5.0         
tidyverse_2.0.0              
**
********

********
Python - 3.9.13

**Python packages
pandas 2.23
fuzzywuzzy 0.18.0         
numpy 1.26.4    
********


********
Mathematica - 13.2
********

****************************************************

*** Additional notes

* The collection of the cases of first impression is described in the manuscript
* The runtime of all analyses should take fewer than 10 minutes. 
* Figures A1 and A2 require setting the seed to (08540) before creating each plot. This is already written into the respective .R files.

****************************************************


*** References
*Boyd, Christina L. 2015. “Federal District Court Judge Ideology Data.” available at: http://cLboyd.net/

*Giles, Micheal W., Virginia A. Hettinger and Todd Peppers. 2001. “Picking Federal Judges: A Note on Policy and Partisan Selection Agendas.” Political Research Quarterly
54(3):623-641.

*Epstein, Lee, Andrew D. Martin, Jeffrey A. Segal and Chad Westerland. 2007. “The Judicial Common Space.” Journal of Law, Economics & Organization 23(2):303–325.

*Federal Judicial Center. 2007. “Federal Judges Biographical Database.” 

*Bonica, Adam, and Maya Sen. (2021). Estimating judicial ideology. Journal of Economic Perspectives, 35(1), 97-118.

*Bonica, Adam, & Maya Sen. (2017). A common-space scaling of the American judiciary and legal profession. Political Analysis, 25(1), 114-121.





